local skel = fk.CreateSkill {
  name = "lb__shizhong",
}

Fk:loadTranslationTable {
  ["lb__shizhong"] = "誓忠",
  [":lb__shizhong"] = "游戏开始时，你选择一名其他角色，其受到其他角色造成的伤害后，你可对伤害来源使用一张无视距离的【杀】，若因此造成的伤害值大于其受到的伤害值，你与〖誓忠〗目标各摸一张牌并重置<a href=':lb__shihong'><font color='red'>〖释洪〗</font></a>。",

  ["@lb__shizhong"] = "誓忠",

  ["#lb__shizhong"] = "誓忠：请选择一名其他角色成为〖誓忠〗目标",
  ["#lb__shizhong_slash"] = "誓忠：你可以对 %src 使用一张无视距离的【杀】，若因此造成的伤害值大于%arg，你与 %dest 各摸一张牌并重置〖释洪〗",

  ["$lb__shizhong1"] = "没什么能阻止我。",
  ["$lb__shizhong2"] = "这点疼痛不足挂齿。",
}

skel:addEffect(fk.Damaged, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and data.from and data.from:isAlive() and player:getMark("@lb__shizhong") == target
        and data.from ~= player and data.from ~= target
        and player:canUseTo(Fk:cloneCard("slash"), data.from, { bypass_distances = true })
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askToUseCard(player, {
      skill_name = skel.name,
      pattern = "slash",
      prompt = "#lb__shizhong_slash:" .. data.from.id .. ":" .. target.id .. ":" .. data.damage,
      cancelable = true,
      extra_data = { bypass_distances = true, must_targets = { data.from.id } }
    })
    if use then
      event:setCostData(self, { use = use })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).use ---@type UseCardDataSpec
    use.extraUse = true
    room:useCard(use)
    if use.damageDealt and target:isAlive() and not player:isNude() then
      local num = 0
      for _, damage in pairs(use.damageDealt) do
        num = num + damage
      end
      if num > data.damage then
        for _, to in ipairs({ player, target }) do
          if to:isAlive() then
            to:drawCards(1, skel.name)
          end
        end
        player:setSkillUseHistory("lb__shihong")
      end
    end
  end,
})

skel:addEffect(fk.GameStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:getOtherPlayers(player)
    if #tos > 1 then
      tos = room:askToChoosePlayers(player, {
        targets = tos,
        min_num = 1,
        max_num = 1,
        skill_name = skel.name,
        cancelable = false,
        prompt = "#lb__shizhong",
      })
    end
    if #tos > 0 then
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@lb__shizhong", event:getCostData(self).tos[1])
  end,
})

skel:addLoseEffect(function(self, player, is_death)
  player.room:setPlayerMark(player, "@lb__shizhong", 0)
end)

return skel